package team.seekers.hula.course.structure.chapter.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.course.structure.chapter.entity.dto.ChapterManageDTO;
import team.seekers.hula.course.structure.chapter.service.ChapterManageService;

/**
 * date: 2022/5/11 10:50
 *
 * @author GH
 * QQ 1124813753
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/chapter")
public class ChapterManageController {

    @Autowired
    private ChapterManageService chapterManageService;

    /**
     * 新增章并级联更新对应课程的章集合顺序
     * @param chapterDTO 需要更新的chapter
     */
    @PostMapping("/create")
    public void save(@RequestBody ChapterManageDTO chapterDTO) {
        chapterManageService.save(chapterDTO);
    }

    /**
     * @param chapterDTO 需要更新的章内容（字段值不为空则更新）
     */
    @PutMapping("/update")
    public void update(@RequestBody ChapterManageDTO chapterDTO) {
        chapterManageService.update(chapterDTO);
    }

//    /**
//     * 删除章并级联更新对应课程的章集合顺序
//     * @param chapterId 需要更新的章id
//     * @param courseId 需要级联更新的课程id
//     * @param chapters 更新后的章id集合（集合元素按课程内章的顺序）
//     */
//    @DeleteMapping("/delete/{chapterId}")
//    public void delete(@PathVariable Long chapterId,
//                       @RequestParam Long courseId,
//                       @RequestBody List<Long> chapters) {
//        CourseManageDTO courseManageDTO = CourseManageDTO.builder()
//                .id(courseId).chapters(chapters).build();
//        chapterManageService.delete(chapterId, courseManageDTO);
//    }
}
